//代理功能
module.exports = function(app) {
  return new Handler(app)
}

var Handler = function(app) {
  this.app = app
  Handler.app = app
  this.sessionService = this.app.get('sessionService')
}
var local = {}
var handler = Handler.prototype

//获取下属玩家列表
handler.getInviterUsers = function(msg,session,next) {
	var uid = session.get("uid")
	if(!uid){
		next(null,{flag : false})
		return
	}
	var begin = msg.begin
	if(!begin || typeof(begin) != "number" || parseInt(begin) != begin){
		begin = 1
	}
	this.app.rpc.db.inviter.getInviterUsers(null,uid,begin,function(flag,data){
		next(null,{flag : flag,data : data})
	})
}
//获取佣金记录
handler.getBrokerageRecord = function(msg,session,next) {
	var uid = session.get("uid")
	if(!uid){
		next(null,{flag : false})
		return
	}
	var begin = msg.begin
	if(!begin || typeof(begin) != "number" || parseInt(begin) != begin){
		begin = 1
	}
	this.app.rpc.db.inviter.getBrokerageRecord(null,uid,begin,function(flag,data){
		next(null,{flag : flag,data : data})
	})
}
//获取总佣金
handler.getAllBrokerage = function(msg,session,next) {
	var uid = session.get("uid")
	if(!uid){
		next(null,{flag : false})
		return
	}
	this.app.rpc.db.inviter.getAllBrokerage(null,uid,function(flag,data){
		next(null,{flag : flag,data : data})
	})
}
//获取提现记录
handler.getWithdrawalRecords = function(msg,session,next) {
	var uid = session.get("uid")
	if(!uid){
		next(null,{flag : false})
		return
	}
	var begin = msg.begin
	if(!begin || typeof(begin) != "number" || parseInt(begin) != begin){
		begin = 1
	}
	this.app.rpc.db.inviter.getWithdrawalRecords(null,uid,begin,function(flag,data){
		next(null,{flag : flag,data : data})
	})
}
